package com.xuerhua.yxt.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xuerhua.yxt.dao.MiddleStudentGradeMapper;
import com.xuerhua.yxt.dao.StudentSignUpMapper;
import com.xuerhua.yxt.dao.StudentSignupUserMapper;
import com.xuerhua.yxt.dao.SysCommentTemplateMapper;
import com.xuerhua.yxt.dao.SysCommonMapper;
import com.xuerhua.yxt.model.MiddleStudentGrade;
import com.xuerhua.yxt.model.StudentSignUp;
import com.xuerhua.yxt.model.StudentSignupUser;
import com.xuerhua.yxt.page.Page;
import com.xuerhua.yxt.reqVo.SignupResultVO;
import com.xuerhua.yxt.service.IStudentSignUpService;

@Service("schoolSignUpService")
public class StudentSignUpServiceImpl implements IStudentSignUpService {

	@Autowired
	private StudentSignUpMapper studentSignUpMapper;
	@Autowired
	private SysCommonMapper sysCommonMapper;
	@Autowired
	private StudentSignupUserMapper studentSignupUserMapper;
	@Autowired
	private MiddleStudentGradeMapper middleStudentGradeMapper;
	
	@Override
	public StudentSignUp selectByPrimaryKey(Integer id) {
		return studentSignUpMapper.selectByPrimaryKey(id);
	}

	@Override
	public int addAndUpdate(StudentSignUp record) {
		if(record.getId() == null) {
			record.setSignupNo(sysCommonMapper.selectStudentSignupNoSeq());
			return studentSignUpMapper.insertSelective(record);
		}
		record.setUpdateTime(new Date());
		return studentSignUpMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public List<StudentSignUp> selectListByPage(Page<StudentSignUp> page) {
		return studentSignUpMapper.selectListByPage(page);
	}

	@Override
	public int updateSignupResult(SignupResultVO record) {
		return studentSignUpMapper.updateSignupResult(record);
	}

	@Override
	public List<StudentSignUp> selectListByUserId(String signupType, Integer userId) {
		return studentSignUpMapper.selectListByUserId(signupType, userId);
	}

	@Override
	public StudentSignupUser selectUserForAdmin(String userAccount, String userPassword) {
		return studentSignupUserMapper.selectUserForAdmin(userAccount, userPassword);
	}

	@Override
	public int addStudentUser(StudentSignupUser record) {
		return studentSignupUserMapper.insertSelective(record);
	}

	@Override
	public List<StudentSignUp> selectListByIds(String signupType, String ids) {
		return studentSignUpMapper.selectListByIds(signupType, ids);
	}

	@Override
	public MiddleStudentGrade selectMiddleStudentGrade(Integer schoolId) {
		return middleStudentGradeMapper.selectMiddleStudentGrade(schoolId);
	}

	@Override
	public int updateMiddleStudentGrade(MiddleStudentGrade record) {
		return middleStudentGradeMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateBatchSignupStatus(List<StudentSignUp> list) {
		return studentSignUpMapper.updateBatchSignupStatus(list);
	}

	@Override
	public int addAndUpdateNewStudent(StudentSignUp studentSignUp) {
		if(studentSignUp.getId() == null) {
			String no = sysCommonMapper.selectNewStudentSignupNoSeq();
			studentSignUp.setSignupNo("X" + no);
			return studentSignUpMapper.insertSelective(studentSignUp);
		}
		studentSignUp.setUpdateTime(new Date());
		return studentSignUpMapper.updateByPrimaryKeySelective(studentSignUp);
	}
}
